<?php
namespace App\Http\Controllers\admin;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use App\Models\Mongodb;
use Illuminate\Http\Request;


class ComplaintController extends Controller
{
      public function index(){
         $data = DB::table('complaint')
             ->leftJoin('user', 'user.open_id', '=', 'complaint.openid')
            ->orderBy('complaint.complaint_time', 'desc')
             ->paginate(10);
             return view('admin.complaint.index',compact('data'));
      }


      //删除
      public function destroy($id)
    {

      DB::table('complaint')->where('id', $id)->delete();
      return  $data = ['status' => 0,'msg' => '删除成功！'];
    }

//日志视图
    public function myLog($type){

        $logs = Mongodb::connectionMongodb('hb_log');
          if($type==0){
              $data = $logs->orderBy('log_time', 'desc')->paginate(16);
          }else{
              $data = $logs->where('type',$type)->orderBy('log_time', 'desc')->paginate(16);
              if ($type==1){
                  $data;
              }elseif ($type==2){
                  $data;
              }elseif ($type==3){
                  $data;
              }elseif ($type==4){
                  $data;
              }
          }
        return view('admin.complaint.mylog',compact('data'));
    }



    //日志删除

    public function logDel(Request $request)
    {
        Mongodb::connectionMongodb('hb_log')->where('_id', $request->id)->delete();
        //return  $data = ['status' => 0,'msg' => '删除成功！'];
        echo "<script>alert('删除成功！');location.href='/admin/mylog';</script>";

    }

}
